package org.gxuwz.core.action;
import java.util.List;
import org.gxuwz.core.entity.TUser;
import org.gxuwz.core.entity.TUserRole;
import org.springframework.beans.factory.annotation.Autowired;
import com.opensymphony.xwork2.ActionSupport;
import org.gxuwz.core.service.*;
import org.gxuwz.core.service.Impl.UserService;

public class LoginAction extends ActionSupport{
	
	@Autowired
	public IUserService  userService;
	private String userid;
	private String roleid;
    private String password;
    private String userType;
    TUser User = new TUser();
    TUserRole UserRole = new TUserRole();
	List<TUser> list;
	List<TUserRole> lists;

	
    public String login()throws Exception{
    	int a=0;
    	String b = "error";
    	boolean bol = userService.validateTUser(userid,password);
		String role = "";
    	if(bol){
    		TUserRole userRole = null;
    		userRole=userService.getRoleId(userid,roleid); 			//从数据库取到对应用户ID的用户角色ID
    		if(!userRole.equals(null)){								//用户角色ID与登录页面传过来的值进行比较
    			
    			if("on".equals(roleid)){					 //roleid=on
    				b="SuperManager";                      
    				System.out.println("1"+role);
    			}else if("R03".equals(roleid)){					//R03
    				System.out.println("2");
    				b="CountyLeader";                       
    			}else if("R04".equals(roleid)){					//R04
    				b="CountyOperator";                      
    				System.out.println("3");

    			}else if("R05".equals(roleid)){				    //R05
    				b="CountrysideOperator";                
    				System.out.println("4");

    			}
    		}
    		else{
    			b="error";
    		}
    	}
    	System.out.println("eeeeeeeeee"+b);
    	return  b;
    
    }
    //添加用户
	
	          //添加用户以及角色
	public IUserService getUserService() {
		return userService;
	}
	public void setUserService(IUserService userService) {
		this.userService = userService;
	}
	public String getUserid() {
		return userid;
	}
	public void setUserid(String userid) {
		this.userid = userid;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getUserType() {
		return userType;
	}
	public void setUserType(String userType) {
		this.userType = userType;
	}
	
	public List<TUser> getList() {
		return list;
	}
	public void setList(List<TUser> list) {
		this.list = list;
	}
	public List<TUserRole> getLists() {
		return lists;
	}
	public void setLists(List<TUserRole> lists) {
		this.lists = lists;
	}

	public String getRoleid() {
		return roleid;
	}

	public void setRoleid(String roleid) {
		this.roleid = roleid;
	}
    	
    
	
	
}
    
    
    
    
 